Clean JavaScript. English Edition by Software Crafters
Author:Software Crafters [Software Crafters]
Language: eng
Format: epub, mobi
Publisher: leanpub.com
Published: 2021-05-16T00:00:00+00:00
Applying the SRP
Returning to the example, one way to separate these responsibilities could be by moving each of the functions of the UseCase class to others, like this :
1 class UseCase{ 2 constructor(repo, notifier){ 3 this.repo = repo; 4 this.notifier = notifier; 5 } 6 7 doSomethingWithTaxes(){ 8 console.log("Do something related with taxes ...") 9 } 10 11 saveChanges(){ 12 this.repo.update(); 13 } 14 15 notify(){ 16 this.notifier.notify("Hi!") 17 } 18 } 19 20 class Repository{ 21 add(){ 22 console.log("Adding in database"); 23 } 24 25 update(){ 26 console.log("Updating in database..."); 27 } 28 29 remove(){ 30 console.log("Deleting from database ..."); 31 } 32 33 find(){ 34 console.log("Finding from database ..."); 35 } 36 } 37 38 39 class NotificationService{ 40 notify(message){ 41 console.log("Sending message ..."); 42 console.log(message); 43 } 44 } 45 46 47 function start(){ 48 const repo = new Repository() 49 const notifier = new NotificationService() 50 const myUseCase = new UseCase(repo, notifier) 51 52 myUseCase.doSomethingWithTaxes(); 53 myUseCase.saveChanges(); 54 myUseCase.notify(); 55 } 56 57 start();
Download
Clean JavaScript. English Edition by Software Crafters.mobi
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25279)
Hello! Python by Anthony Briggs(24330)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23419)
Kotlin in Action by Dmitry Jemerov(22500)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21953)
Dependency Injection in .NET by Mark Seemann(21835)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20697)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19514)
Grails in Action by Glen Smith Peter Ledbrook(18592)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17028)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15836)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13683)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11845)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11149)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10619)
Hit Refresh by Satya Nadella(9185)
The Kubernetes Operator Framework Book by Michael Dame(8560)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8398)
Robo-Advisor with Python by Aki Ranin(8344)